# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgbase=deepin-wallpapers
pkgname=(deepin-wallpapers deepin-community-wallpapers)
pkgver=1.7.7
pkgrel=2
epoch=1
pkgdesc='Deepin Wallpapers'
arch=('any')
license=('GPL')
url="https://github.com/linuxdeepin/deepin-wallpapers"
makedepends=('deepin-api')
source=("$pkgbase-$pkgver.tar.gz::https://github.com/linuxdeepin/deepin-wallpapers/archive/$pkgver.tar.gz")
sha512sums=('11c049d9e5a5864340c989447e2c8b1f423256ed64813071d23bec75c4ee6c0d8de119018c119ea35aee55971a153bf0105e9284880a0aa310b08fb261fbf4df')

prepare() {
  cd $pkgbase-$pkgver
  cp -a "$srcdir"/$pkgbase-$pkgver{,-community}
}

build() {
  cd "$srcdir"/$pkgbase-$pkgver
  for _pic in deepin/*; do
    make PICS=$_pic
  done

  cd "$srcdir"/$pkgbase-$pkgver-community
  for _pic in deepin-community/*; do
    make PICS=$_pic
  done
}

package_deepin-wallpapers() {
  pkgdesc='Default wallpapers for DDE'
  groups=('deepin')

  cd $pkgbase-$pkgver
  install -dm755 "$pkgdir"/usr/share/wallpapers
  cp -r deepin "$pkgdir"/usr/share/wallpapers/

  install -dm755 "$pkgdir"/var/cache
  cp -r image-blur "$pkgdir"/var/cache/

  # Suggested by upstream
  install -dm755 "$pkgdir"/usr/share/backgrounds/deepin
  ln -s ../../wallpapers/deepin/Hummingbird_by_Shu_Le.jpg "$pkgdir"/usr/share/backgrounds/deepin/desktop.jpg
  ln -s $(echo -n /usr/share/wallpapers/deepin/Hummingbird_by_Shu_Le.jpg | md5sum | cut -d " " -f 1).jpg \
        "$pkgdir"/var/cache/image-blur/$(echo -n /usr/share/backgrounds/deepin/desktop.jpg | md5sum | cut -d " " -f 1).jpg
}

package_deepin-community-wallpapers() {
  pkgdesc='Community wallpapers for DDE'
  groups=('deepin-extra')

  cd $pkgbase-$pkgver-community
  install -dm755 "$pkgdir"/usr/share/wallpapers/deepin
  cp deepin-community/* "$pkgdir"/usr/share/wallpapers/deepin/

  install -dm755 "$pkgdir"/var/cache
  cp -r image-blur "$pkgdir"/var/cache/
}
